// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

#include <gtest/gtest.h>

#include "DBManager/IService/Result/Nodal/IACCELERATIONService.h"

#include "../../TestDB.h"

using namespace SG::DataStructure::Post;
using namespace SG::DBManager;

TEST (O_Nodal, IACCELERATIONService)
{
    DB::ServiceFactory->ClearDatabase ();
    // 获取仓库服务
    auto service = DB::ServiceFactory->get<IACCELERATIONService> ();
    // 创建存储的数据，添加数据
    std::vector<ACCELERATIONData> saveData;

    ACCELERATIONData data;

    for (size_t i = 0; i < 10; i++)
    {
        data.m_id       = i;
        data.m_domainId = 1;
        saveData.push_back (data);
    }
    ASSERT_EQ (service->Add ({ SG::DataStructure::FEM::SOLType::SOL_SESTATIC, 1 }, saveData),
               SG::DataStructure::Common::Status::STATUS_Success);  // adds内部会清空saveData数据

    saveData.clear ();
    // 创建存储的数据，添加数据
    for (size_t i = 0; i < 10; i++)
    {
        data.m_id       = i;
        data.m_domainId = 2;
        saveData.push_back (data);
    }
    ASSERT_EQ (service->Add ({ SG::DataStructure::FEM::SOLType::SOL_SESTATIC, 2 }, saveData),
               SG::DataStructure::Common::Status::STATUS_Success);

    // 创建判断的数据
    for (size_t i = 0; i < 10; i++)
    {
        data.m_id       = i;
        data.m_domainId = 2;
        saveData.push_back (data);
    }

    // 通过DomainId获取数据，测试接口正确性
    std::vector<ACCELERATIONData> result;
    ASSERT_TRUE (service->Find (2, result) == SG::DataStructure::Common::Status::STATUS_Success);

    // ASSERT_EQ (result.size (), 10);
    // for (size_t i = 0; i < 10; i++)
    // {
    //     ASSERT_EQ (saveData[i].m_id, result[i].m_id);

    //     ASSERT_EQ (saveData[i].m_domainId, result[i].m_domainId);
    // }

    // // 通过DomainId与实体ID获取数据，测试接口正确性
    // ACCELERATIONData singleResylt;
    // ASSERT_TRUE (service->Find (2, 1, singleResylt));
    // ASSERT_EQ (singleResylt.m_id, 1);
    // ASSERT_EQ (singleResylt.m_domainId, 2);
}
